package com.wm.blog_gateway.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wm.blog_common.bean.QueryPage;
import com.wm.blog_common.domain.TRouteDO;
import com.wm.blog_common.entity.TRoute;
import com.wm.blog_common.result.Result;
import com.wm.blog_gateway.query.TRouteQuery;
import com.wm.blog_gateway.service.TRouteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wm_yu
 * @since 2020-03-27
 */
@Slf4j
@RestController
@RequestMapping("/web/route")
public class TRouteController {

    @Autowired
    private TRouteService tRouteService;

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<TRouteDO> get(@PathVariable Long id) {
        return tRouteService.selectById(id);
    }

    /**
     * 根据ID删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> delete(@PathVariable Long id){
        return tRouteService.deleteById(id);
    }

    /**
     * 添加
     * @param tRoute
     * @return
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody TRoute tRoute){
        return tRouteService.insert(tRoute);
    }

    /**
     * 修改
     * @param tRoute
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody TRoute tRoute){
        return tRouteService.update(tRoute);
    }

    /**
     * 分页查询
     * @param current   查询页
     * @param size   每页显示条数
     * @param query 查询参数
     * @return
     */
    @GetMapping("/page")
    public Result<Page<TRouteDO>> page(Integer current, Integer size, TRouteQuery query){
        return tRouteService.page(new QueryPage(current,size),query);
    }


    /**
     * 刷新路由
     */
    @GetMapping("/refresh")
    public Result refresh() {
      return tRouteService.refresh();
    }

}
